home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 424_02 / ED-157 / direntpc.h < prev    next >
C/C++ Source or Header  |  1993-11-18  |  2KB  |  80 lines

  1. /*
  2.  * Copyright (C) 1993 by Charles Sandmann (sandmann@clio.rice.edu)
  3.  * 
  4.  * This file is part of ED.
  5.  * 
  6.  * ED is free software; you can redistribute it and/or modify it under the terms
  7.  * of the GNU General Public License as published by the Free Software Foundation.
  8.  * 
  9.  * ED is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  10.  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  11.  * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  12.  * 
  13.  * You should have received a copy of the GNU General Public License along with ED
  14.  * (see the file COPYING).  If not, write to the Free Software Foundation, 675
  15.  * Mass Ave, Cambridge, MA 02139, USA.
  16.  */
  17.  
  18. #ifdef WIN32
  19. /* This provides opendir,readdir,closedir function subset for ED in NT */
  20. #include <windows.h>
  21.  
  22. struct dirent {
  23.     char d_name[256];
  24. };
  25.  
  26. typedef struct direct {
  27.     char d_name[256];
  28.     int d_first;
  29.     HANDLE d_hFindFile;
  30. } DIR;
  31.  
  32. DIR *opendir(n)
  33. char *n;                        /* directory to open */
  34. {
  35.     DIR *d;                        /* malloc'd return value */
  36.     char *p;                    /* malloc'd temporary string */
  37.     WIN32_FIND_DATA fd;
  38.  
  39.     d = (DIR *)imalloc(sizeof(DIR));
  40.     p = (Char *)imalloc(strlen(n) + 5);
  41.     strcpy(p,n);
  42.     strcat(p,"/*.*");
  43.     d->d_hFindFile = FindFirstFile(p,&fd);
  44.     ifree(p);
  45.     if(d->d_hFindFile == INVALID_HANDLE_VALUE)
  46.     {
  47.         ifree(d);
  48.         return NULL;
  49.     }
  50.     strcpy(d->d_name,fd.cFileName);
  51.     d->d_first = 1;
  52.     return d;
  53. }
  54.  
  55. struct dirent *readdir(d)
  56. DIR *d;                             /* directory stream to read from */
  57. /* Return pointer to first or next directory entry, or NULL if end. */
  58. {
  59.     WIN32_FIND_DATA fd;
  60.  
  61.     if(d->d_first)
  62.         d->d_first = 0;
  63.     else if(!FindNextFile(d->d_hFindFile,&fd))
  64.         return NULL;
  65.     else
  66.         strcpy(d->d_name,fd.cFileName);
  67.     return (struct dirent *)d;
  68. }
  69.  
  70. int closedir(d)
  71. DIR *d;
  72. {
  73.     int i;
  74.  
  75.     i = FindClose(d->d_hFindFile);
  76.     ifree(d);
  77.     return i;
  78. }
  79. #endif
  80.